from utils.wrapper import *
import re


def check_contact_post(request):
    # 获取留言用户名
    user_name = post(request,"user_name")
    # 获取留言用户联系方式
    user_tel = post(request,"user_tel")
    # 获取留言信息
    user_msg = post(request,"user_msg")

    re_tel = re.match("^1[3458]\d{9}$|^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$",user_tel,re.I)

    flag = True

    if user_name == "" or user_tel == "" or user_msg == "":
        add_message(request,"error_msg","以上不能为空哦~~")
        flag = False

    if len(user_name) > 10:
        add_message(request, "error_name", "用户名长度不能大于10~~")
        flag = False

    if not re_tel:
        add_message(request, "error_tel", "手机或邮箱格式不正确~~")
        flag = False

    if len(user_msg) >160:
        add_message(request, "error_msg", "留言长度不能超过160~~")
        flag = False

    return flag






